package main;

import com.alibaba.fastjson.parser.ParserConfig;
import configuration.RobConfiguration;
import enumeration.EnumCourseType;
import enumeration.EnumRobChannel;
import enumeration.EnumUserType;
import http.BasicRequest;
import http.util.PrintUtil;
import main.strategy.SelectStrategyFactory;
import mysql.MysqlUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import timer.saveCookieManager;
import timer.saveCoursesManager;
import timer.saveRobberManager;
import user.*;
import user.impl.BetterUser;
import user.impl.OOUser;
import user.impl.robUser.RobUser;

import java.util.*;

import static http.util.PrintUtil.printTitle;
import static http.util.PrintUtil.showIntroduction;

public class robClass {

    public static Logger logger = Logger.getLogger(robClass.class);
    private static ArrayList<IUser> ooUsers;

    /**
     * 注册用户
     */
    public static RobUser register(String username) {

        RobUser user = null;
        Scanner strInput = new Scanner(System.in, "UTF-8");
        if (RobConfiguration.ROB_LOGIN_MODE.equals(EnumUserType.BETTER_USER)) {
            user = new BetterUser();
        }
        if (RobConfiguration.ROB_LOGIN_MODE.equals(EnumUserType.OO_USER)) {
            user = new OOUser();
        }

        robClass.logger.info("填写个人信息");
        if (StringUtils.isBlank(username)) {
            robClass.logger.info("正方账号:");
            if (strInput.hasNext()) user.setUsername(strInput.next());
        } else {
            user.setUsername(username);
        }

        robClass.logger.info("正方密码:");
        if (strInput.hasNext()) user.setPassword(strInput.next());
        user.setRobEnable(1);

        UserManager.addUserCache(user);
        MysqlUtil.updateUser(user);
        return user;
    }

    public static void showTable(IUser user) {
        showIntroduction();
        Scanner keyBoardInput = new Scanner(System.in, "UTF-8");
        if (keyBoardInput.hasNextInt()) {
            int input = keyBoardInput.nextInt();
            switch (input) {
                /***************初级录入***************/
                case 10: /**注册账号*/
                    SelectStrategyFactory.Register.execute(null);
                    break;
                case 11: /**修改账号信息*/
                    SelectStrategyFactory.Register.execute(user);
                    break;
                /***************高级录入***************/
                case 12: /**高级注册抢课信息*/
                    for (IUser user2 : ooUsers) {
                        if (((RobUser) user2).getRobClasses().isEmpty()) {
                            if (RobConfiguration.ROB_COURSE_TYPE.equals(EnumCourseType.PE)) {
                                SelectStrategyFactory.SelectPECourseList.execute(user2);
                            }
                            if (RobConfiguration.ROB_COURSE_TYPE.equals(EnumCourseType.COMMON)) {
                                SelectStrategyFactory.SelectCommonCourseList.execute(user2);
                            }
                        }
                    }
                    break;
                case 13: /**登录尝试*/
                    SelectStrategyFactory.Login.execute(user);
                    break;
                /***************查找/修改课程列表***************/
                case 20: /**选择体育课*/
                    SelectStrategyFactory.SelectPECourseList.execute(user);
                    break;
                case 21: /**选择公选课*/
                    SelectStrategyFactory.SelectCommonCourseList.execute(user);
                    break;
                /***************体育课***************/
                case 50: /**体育课个人立刻抢课*/
                    printTitle("体育课 - (个人)开始[立刻]抢课");
                    SelectStrategyFactory.StartPERob.execute(user);
                    break;
                case 51: /**体育课个人定时抢课*/
                    printTitle("体育课 - (个人)开始[定时]抢课");
                    SelectStrategyFactory.StartPERobTimer.execute(user);
                    break;
                case 52: /**体育课全体立刻抢课*/
                    printTitle("体育课 - (全体)开始[立刻]抢课#(#OOUSER#BetterUser#)");
                    UserManager.getAllUserCache().parallelStream().forEach(u -> SelectStrategyFactory.StartPERob.execute(u));
                    break;
                case 53:/**体育课全体定时抢课*/
                    printTitle("体育课 - (全体)开始[定时]抢课#(#OOUSER#BetterUser#)");
                    UserManager.getAllUserCache().parallelStream().forEach(u -> SelectStrategyFactory.StartPERobTimer.execute(u));
                    break;
                case 54: /**体育课狂暴模式抢课*/
                    printTitle("体育课 - (个人)开始[立刻]狂暴模式抢课 x5 #(#OOUSER#BetterUser#)");
                    SelectStrategyFactory.StartPECrazyRob.execute(user);
                    break;
                case 55: /**体育课狂暴模式抢课*/
                    printTitle("体育课 - (全体)开始[立刻]狂暴模式抢课 x5 #(#OOUSER#BetterUser#)");
                    UserManager.getAllUserCache().parallelStream().forEach(u -> SelectStrategyFactory.StartPECrazyRob.execute(u));
                    break;
                /***************公选/创新课***************/
                case 60: /**公选课个人立刻抢课*/
                    printTitle("公选课 - (个人)开始[立刻]抢课");
                    SelectStrategyFactory.StartCommonRob.execute(user);
                    break;
                case 61: /**公选课个人定时抢课*/
                    printTitle("公选课 - (个人)开始[定时]抢课");
                    SelectStrategyFactory.StartCommonRobTimer.execute(user);
                    break;
                case 62: /**公选课全体立刻抢课*/
                    printTitle("公选课 - (全体)开始[立刻]抢课#(#OOUSER#BetterUser#)");
                    UserManager.getAllUserCache().parallelStream().forEach(u -> SelectStrategyFactory.StartCommonRob.execute(u));
                    break;
                case 63:/**公选课全体定时抢课*/
                    printTitle("公选课 - (全体)开始[定时]抢课#(#OOUSER#BetterUser#)");
                    UserManager.getAllUserCache().parallelStream().forEach(u -> SelectStrategyFactory.StartCommonRobTimer.execute(u));
                    break;
                case 64: /**公选课狂暴模式抢课*/
                    printTitle("公选课 - (个人)开始[立刻]狂暴模式抢课 x5 #(#OOUSER#BetterUser#)");
                    SelectStrategyFactory.StartCommonCrazyRob.execute(user);
                    break;
                case 65: /**公选课狂暴模式抢课*/
                    printTitle("公选课 - (全体)开始[立刻]狂暴模式抢课 x5 #(#OOUSER#BetterUser#)");
                    UserManager.getAllUserCache().parallelStream().forEach(u -> SelectStrategyFactory.StartCommonCrazyRob.execute(u));
                    break;
                /***************运行与维护***************/
                case 70: /**手动备份课表*/
                    SelectStrategyFactory.BackupCourseList.execute(user);
                    break;
                /***************密码撞库（不可用）***************/
                case 100: /**密码撞击*/
                    BasicRequest basicRequest = new BasicRequest();
                    String uri = "/default4.aspx?xh=1908010101&0";
                    String ram_password = "";
                    char c[] = ram_password.toCharArray();
                    rec(c, 0);
//                    for (int i = 0; i <= 3; i++) {
//                        char c[] = ram_password.toCharArray();
//                        c[i] = Character.toUpperCase(c[i]);
////                        System.out.println(c);
//                        temp(basicRequest, uri, c);
//                        for (int j = i + 1; j <= 3; j++) {
//                            c[j] = Character.toUpperCase(c[j]);
////                            System.out.println(c);
//                            temp(basicRequest, uri, c);
//                            for (int jj = j + 1; jj <= 3; jj++) {
//                                c[jj] = Character.toUpperCase(c[jj]);
////                                System.out.println(c);
//                                temp(basicRequest, uri, c);
//                                for (int jjj = jj + 1; jjj <= 3; jjj++) {
//                                    c[jjj] = Character.toUpperCase(c[jjj]);
//
//                                    temp(basicRequest, uri, c);
////                                            String responseHtml = basicRequest.post.("/default4.aspx?xh=" + super.getUsername() + "&" + super.getUid(), bodyContent, super.getUsername() + super.getUid());
////                                    if (responseHtml != null) {
////                                        String parseResult = ParseUtil.parseScript(responseHtml);
////                                        if (parseResult == null) {
////                                            robClass.logger.info("正方系统 - 登录成功");
////                                        } else {
////                                            robClass.logger.info("正方系统 - 登录失败");
////
////                                        }
////                                    }
//                                }
//                            }
//                        }
//                    }
                    break;
//                case 88:
//                    CommonRobber robber = new CommonRobber(user);
//                    AbstractUser abstractUser = (AbstractUser) robber.getUser();
//                    RobConfiguration.isCrazyRobMode = false;
//                    MysqlUtil.getAbstractRobber(robber, user.getUsername());
//                    ScheduledExecutorService preRobThread = Executors.newScheduledThreadPool(200);
//                    preRobThread.scheduleAtFixedRate(new TimerTask() {
//                        @Override
//                        public void run() {
//                            String cookie = abstractUser.getRandomCookie();
//                            try {
////                                    robClass.logger.info("正在抢课 - TestThread Start");
//                                try {
//
//                                    try {
//                                        System.out.println("执行登录");
//                                        robber.getUser().login();
//                                    } catch (LoginErrorException e) {
//                                        e.printStackTrace();
//                                    }
//
//
//                                    System.out.println("登录后使用的Cookie:" + cookie);
//                                    if (cookie == null) {
//                                        return;
//                                    }
//                                    Request request_main = robber.getBasicRequest().getBasicRequest().newBuilder()
//                                            .addHeader("cookie", cookie)
//                                            .addHeader("cache-control", "no-cache")
//                                            .addHeader("pragma", "no-cache")
//                                            .addHeader("Upgrade-Insecure-Requests", "1")
//                                            .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36")
//                                            .url(RobConfiguration.URL + "/xs_main.aspx?xh=" + user.getUsername())
//                                            .get()
//                                            .build();
//                                    Call call_main = robber.getBasicRequest().getPreInitClient().newCall(request_main);
//                                    call_main.enqueue(new Callback() {
//                                        @Override
//                                        public void onFailure(Call call, IOException e) {
//                                        }
//
//                                        @Override
//                                        public void onResponse(Call call, Response response) {
//                                            try {
//                                                call = robber.getBasicRequest().common_async_getWithCookie("/xf_xsqxxxk.aspx?xh=" + user.getUsername() + "&xm=" + URLEncoder.encode(user.getStudentName(), "gb2312") + "&gnmkdm=N121203", user, cookie);
//                                                if (call == null) {
//                                                    return;
//                                                }
//                                                call.enqueue(new Callback() {
//                                                    /**网络获取失败 - 使用本地公选课表缓存*/
//                                                    @Override
//                                                    public void onFailure(Call call, IOException e) {
//                                                        robClass.logger.info("异步-获取公选课表失败: 网络请求超时");
//                                                        if (robber.getIdAndCourseNameCache().isEmpty()) {
//                                                            robClass.logger.info("异步-获取公选课表失败, 由于用户课表为空, 使用缓存课表#" + saveCoursesManager.getGlobalIdAndCourseNameCache().size());
//                                                            robber.setIdAndCourseNameCache(saveCoursesManager.getGlobalIdAndCourseNameCache());
//                                                        }
//                                                    }
//
//                                                    @Override
//                                                    public void onResponse(Call call, Response response) throws IOException {
//                                                        String responseHtml = response.body().string();
////                                                             System.out.println("异步获取课程结果" + responseHtml);
//                                                        response.close();
//                                                        HtmlUtil.parseCommonSelectCourseList(responseHtml, robber.getIdAndCourseNameCache(), false);
//                                                        String firstViewState = HtmlUtil.getViewStateFromResponseHtml(responseHtml);
//                                                        //用这个fsv去再次访问一次
//                                                        /**同步获取第二个viewstate*/
////                                                             System.out.println("fvs:" + firstViewState);
//                                                        if (StringUtils.isBlank(firstViewState)) {
//                                                            return;
//                                                        }
//                                                        /**
//                                                         * 优化思路
//                                                         * 第一个viewState获取后 缓存下来
//                                                         * 获取第二个viewState 缓存下来
//                                                         * 再根据第二个viewState不断发包*/
//
//                                                        /**获取第二个ViewState*/
//                                                        String bodyContent = "&__EVENTTARGET=dpkcmcGrid%3AtxtPageSize&__EVENTARGUMENT=&ddl_kcxz=&ddl_ywyl=%D3%D0&ddl_kcgs=&ddl_xqbs=1&ddl_sksj=&TextBox1=&Button2=%C8%B7%B6%A8&dpkcmcGrid%3AtxtChoosePage=1&dpkcmcGrid%3AtxtPageSize=150";
//                                                        Request request = null;
//                                                        try {
//                                                            String out = "__VIEWSTATE=" +
//                                                                    URLEncoder.encode(firstViewState, "gb2312") +
//                                                                    bodyContent;
//                                                            request = robber.getBasicRequest().getBasicRequest().newBuilder()
//                                                                    .addHeader("referer", RobConfiguration.URL + "/xf_xsqxxxk.aspx?xh=" + user.getUsername() + "&xm=" + URLEncoder.encode(user.getStudentName(), "gb2312") + "&gnmkdm=N121203")
//                                                                    .addHeader("cookie", cookie)
//                                                                    .addHeader("cache-control", "no-cache")
//                                                                    .addHeader("pragma", "no-cache")
//                                                                    .url(RobConfiguration.URL + "/xf_xsqxxxk.aspx?xh=" + user.getUsername() + "&xm=" + URLEncoder.encode(user.getStudentName(), "gb2312") + "&gnmkdm=N121203")
//                                                                    .post(RequestBody.create(MediaType.parse("application/x-www-form-urlencoded;charset=gb2312"), out))
//                                                                    .build();
//                                                            //System.out.println(out);
//                                                        } catch (UnsupportedEncodingException e) {
//                                                            e.printStackTrace();
//                                                        }
//
//
//                                                        String res = null;
//                                                        try {
//                                                            response = robber.getBasicRequest().getPreInitClient().newCall(request).execute();
//                                                            res = response.body().string();
////                                                                 System.out.println(res);
//                                                            firstViewState = HtmlUtil.getViewStateFromResponseHtml(res);
////                                                                 System.out.println("最终:" + firstViewState);
//                                                        } catch (Exception e) {
//                                                        }
//                                                        if (!StringUtil.isBlank(firstViewState)) {
//                                                            robber.setFvs(firstViewState);
////                                                               System.out.println("设置Fvs");
//                                                            /**获取FirstViewState后进行序列化备份*/
////                                                                saveCookieManager.updateUserToGlobalIdAndCookies(robber.getUser());
////                                                                saveRobberManager.updateUserToGlobalIdAndRobberInfo(robber);
//                                                            /**抢课逻辑*/
//
//                                                            try {
//                                                                bodyContent = "&ddl_kcxz=&ddl_ywyl=%D3%D0&ddl_kcgs=&ddl_xqbs=1&ddl_sksj=&TextBox1=";
//                                                                StringBuilder sb = new StringBuilder(bodyContent);
//                                                                for (int i = 2; i <= 42; i++) {
//                                                                    boolean select = false;
//                                                                    for (String courseId : ((RobUser) (robber.getUser())).getRobClasses()) {
//                                                                        if (saveCoursesManager.getGlobalIdAndCourseNameCache().isEmpty()) {
//                                                                            System.out.println("saveCoursesManager.getGlobalIdAndCourseNameCache() 为空");
//                                                                            return;
//                                                                        }
//                                                                        Integer num2 = Integer.valueOf(saveCoursesManager.getGlobalIdAndCourseNameCache().get(courseId).split(":")[1].split(":")[0].split("ctl")[1]);
//                                                                        if (i == num2) {
//                                                                            sb.append("&" + URLEncoder.encode(saveCoursesManager.getGlobalIdAndCourseNameCache().get(courseId), "gb2312") + "=on");
//                                                                            select = true;
//                                                                            break;
//                                                                        }
//                                                                    }
//                                                                    if (!select) {
//                                                                        sb.append("&kcmcGrid%3A_ctl" + i + "%3Ajcnr=%7C%7C%7C");
//                                                                    }
//                                                                }
//                                                                bodyContent = sb.toString() + "&dpkcmcGrid%3AtxtChoosePage=1&dpkcmcGrid%3AtxtPageSize=150&Button1=++%CC%E1%BD%BB++";
//                                                                if (StringUtils.isBlank(robber.getFvs())) {
//                                                                    return;
//                                                                }
////                                                                     System.out.println("rob-getFvs():" + robber.getFvs());
//                                                                responseHtml = robber.getBasicRequest().postCommonWithLoginCookieAndViewState2("/xf_xsqxxxk.aspx?xh=" + user.getUsername() + "&xm=" + URLEncoder.encode(user.getStudentName(), "gb2312") + "&gnmkdm=N121203", bodyContent, user.getUsername(), robber.getFvs(), user, cookie);
//                                                                if (responseHtml != null) {
//                                                                    robber.setPostViewState(HtmlUtil.getViewStateFromResponseHtml(responseHtml));
//                                                                    Document doc = Jsoup.parse(responseHtml);
//                                                                    Elements alert = doc.select("script");
////                                                                         System.out.println(responseHtml);
//                                                                    if (alert != null) {
//                                                                        for (int ii = 0; ii < 2; ii++) {
//                                                                            if (alert.get(ii).html() != null) {
//                                                                                if (alert.get(ii).html().split("alert\\('").length > 1) {
//                                                                                    System.out.println(user.getStudentName() + " " + alert.get(ii).html().split("alert\\('")[1].split("'")[0]);
//                                                                                }
//
//                                                                            }
//                                                                        }
//                                                                    }
//                                                                }
//
//                                                            } catch (UnsupportedEncodingException e) {
//                                                                e.printStackTrace();
//                                                            } catch (IOException e) {
//                                                                e.printStackTrace();
//                                                            }
//                                                        }
//                                                    }
//                                                });
//                                            } catch (Exception e) {
//                                                robClass.logger.info(user.getUsername() + "#搜索课程失败");
//                                            }
//                                        }
//                                    });
//                                } catch (Exception e) {
//                                    e.printStackTrace();
//                                }
//
//                            } catch (Exception e) {
//                                e.printStackTrace();
//                            }
//                            try {
//                                Thread.sleep(1000);
//                            } catch (InterruptedException e) {
//                                e.printStackTrace();
//                            }
//                        }
//
//                    }, 0, 1000, TimeUnit.MILLISECONDS); /**定时增加抢课资源初始化线程*/
//                    ScheduledExecutorService robThread = Executors.newScheduledThreadPool(500);
//                    robThread.scheduleAtFixedRate(new TimerTask() {
//                                                      @Override
//                                                      public void run() {
//                                                          if (!StringUtils.isBlank(robber.getFvs())) {
//                                                              String cookie = abstractUser.getRandomCookie();
//                                                              System.out.println("gogogo2");
//                                                              try {
//                                                                  String bodyContent = "&ddl_kcxz=&ddl_ywyl=%D3%D0&ddl_kcgs=&ddl_xqbs=1&ddl_sksj=&TextBox1=";
//                                                                  StringBuilder sb = new StringBuilder(bodyContent);
//                                                                  for (int i = 2; i <= 42; i++) {
//                                                                      boolean select = false;
//                                                                      for (String courseId : ((RobUser) (robber.getUser())).getRobClasses()) {
//                                                                          if (saveCoursesManager.getGlobalIdAndCourseNameCache().isEmpty()) {
//                                                                              System.out.println("saveCoursesManager.getGlobalIdAndCourseNameCache() 为空");
//                                                                              return;
//                                                                          }
//                                                                          Integer num2 = Integer.valueOf(saveCoursesManager.getGlobalIdAndCourseNameCache().get(courseId).split(":")[1].split(":")[0].split("ctl")[1]);
//                                                                          if (i == num2) {
//                                                                              sb.append("&" + URLEncoder.encode(saveCoursesManager.getGlobalIdAndCourseNameCache().get(courseId), "gb2312") + "=on");
//                                                                              select = true;
//                                                                              break;
//                                                                          }
//                                                                      }
//                                                                      if (!select) {
//                                                                          sb.append("&kcmcGrid%3A_ctl" + i + "%3Ajcnr=%7C%7C%7C");
//                                                                      }
//                                                                  }
//                                                                  bodyContent = sb.toString() + "&dpkcmcGrid%3AtxtChoosePage=1&dpkcmcGrid%3AtxtPageSize=150&Button1=++%CC%E1%BD%BB++";
//                                                                  if (StringUtils.isBlank(robber.getFvs())) {
//                                                                      return;
//                                                                  }
////                                                                     System.out.println("rob-getFvs():" + robber.getFvs());
//                                                                  String responseHtml = robber.getBasicRequest().postCommonWithLoginCookieAndViewState2("/xf_xsqxxxk.aspx?xh=" + user.getUsername() + "&xm=" + URLEncoder.encode(user.getStudentName(), "gb2312") + "&gnmkdm=N121203", bodyContent, user.getUsername(), robber.getFvs(), user, cookie);
//                                                                  if (responseHtml != null) {
//                                                                      robber.setPostViewState(HtmlUtil.getViewStateFromResponseHtml(responseHtml));
//                                                                      Document doc = Jsoup.parse(responseHtml);
//                                                                      Elements alert = doc.select("script");
////                                                                         System.out.println(responseHtml);
//                                                                      if (alert != null) {
//                                                                          for (int ii = 0; ii < 2; ii++) {
//                                                                              if (alert.get(ii).html() != null) {
//                                                                                  if (alert.get(ii).html().split("alert\\('").length > 1) {
//                                                                                      System.out.println(user.getStudentName() + " " + alert.get(ii).html().split("alert\\('")[1].split("'")[0]);
//                                                                                  }
//
//                                                                              }
//                                                                          }
//                                                                      }
//                                                                  }
//
//                                                              } catch (UnsupportedEncodingException e) {
//                                                                  e.printStackTrace();
//                                                              } catch (IOException e) {
//                                                                  e.printStackTrace();
//                                                              }
//                                                          }
//                                                          try {
//                                                              Thread.sleep(50);
//                                                          } catch (InterruptedException e) {
//                                                              e.printStackTrace();
//                                                          }
//                                                      }
//                                                  },
//                            5000, 10, TimeUnit.MILLISECONDS);
//                    break;
                case 0:
                    System.exit(0);
                    break;
            }
        }
    }

    /**
     * 撞密码的临时代码
     */
    public static void rec(char[] c, int i) {
        if (i == 4) {
            return;
        } else {
            BasicRequest basicRequest = new BasicRequest();
            String uri = "/default4.aspx?xh=1908010101&0";

            c[i] = Character.toUpperCase(c[i]);
//        System.out.println(i+" #转成大写"+String.valueOf(c));
            temp(basicRequest, uri, String.valueOf(c));
            rec(c, i + 1);

            c[i] = Character.toLowerCase(c[i]);
            temp(basicRequest, uri, String.valueOf(c));
            rec(c, i + 1);
        }
    }

    /**
     * 撞密码的临时代码
     */
    public static void temp(BasicRequest basicRequest, String uri, String c) {
        String bodyContent = "__VIEWSTATE=dDwxMTE4MjQwNDc1Ozs%2B%2BOcVL6V79a6y5AS0L93bcGUk638%3D&TextBox1=1908010101&TextBox2=" + c + "&RadioButtonList1=%D1%A7%C9%FA&Button1=+%B5%C7+%C2%BC+";
        basicRequest.login(new OOUser(), uri, bodyContent, Long.valueOf(1908010101));
    }

    public static void main(String[] args) {

        /**代理设置 用于fiddler postman 等 抓包工具进行网络包分析*/
//        System.setProperty("http.proxyHost", "192.168.123.233");
//        System.setProperty("https.proxyHost", "192.168.123.233");
        System.setProperty("http.proxyHost", "127.0.0.1");
        System.setProperty("https.proxyHost", "127.0.0.1");
        System.setProperty("http.proxyPort", "8888");
        System.setProperty("https.proxyPort", "8888");
        try {
            RobUser user = null;
            ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
            Scanner selectInput = new Scanner(System.in, "UTF-8");
            PrintUtil.printTitle("请选择抢课通道:默认本科");
            robClass.logger.info("0.本科");
            robClass.logger.info("1.专科");
            int input = selectInput.nextInt();
            switch (input) {
                case 1: /**设置抢课通道 - 本科*/
                    RobConfiguration.IP = "192.168.170.23";
                    RobConfiguration.URL = "http://" + RobConfiguration.IP;
                    RobConfiguration.USERNAME_MAX_LENGTH = RobConfiguration.SPECIALITY_USERNAME_MAX_LENGTH;
                    RobConfiguration.ROB_CHANNEL = EnumRobChannel.SPECIALITY;
                    RobConfiguration.SECRETCODE_URL = RobConfiguration.URL + "/CheckCode.aspx";
                    robClass.logger.info(RobConfiguration.USERNAME_MAX_LENGTH);

                    break;
                default: /**设置抢课通道 - 专科*/
                    RobConfiguration.IP = "192.168.170.253";
                    RobConfiguration.URL = "http://" + RobConfiguration.IP;
                    RobConfiguration.USERNAME_MAX_LENGTH = RobConfiguration.UNDERGRADUATE_USERNAME_MAX_LENGTH;
                    RobConfiguration.ROB_CHANNEL = EnumRobChannel.UNDERGRADUATE;
                    break;
            }

            /**登录方式*/
            PrintUtil.printTitle("请选择注册线路");
            robClass.logger.info("0.oldUser - 原始绕过验证码通道");
            robClass.logger.info("1.betterUser - 自动绕过验证码通道");
            int input2 = selectInput.nextInt();
            switch (input2) { /**旧登录方式 依靠default4.aspx网页 绕过验证码登录*/
                case 0:
                    RobConfiguration.ROB_LOGIN_MODE = EnumUserType.OO_USER;
                    ooUsers = MysqlUtil.getAllUser(EnumUserType.OO_USER);
                    break;
                case 1: /**新方式登录 首页网页进行验证码识别*/
                    RobConfiguration.ROB_LOGIN_MODE = EnumUserType.BETTER_USER;
                    ooUsers = MysqlUtil.getAllUser(EnumUserType.BETTER_USER);
                    break;
            }
            robClass.logger.info("你选择了:" + RobConfiguration.ROB_LOGIN_MODE);

            /**要抢课程类型*/
            PrintUtil.printTitle("请选择课程类型");
            robClass.logger.info("0.体育课(PE)");
            robClass.logger.info("1.公选/创新课(Common)");
            int courseTypeinput = selectInput.nextInt();
            switch (courseTypeinput) {
                case 0: /**体育课*/
                    RobConfiguration.ROB_COURSE_TYPE = EnumCourseType.PE;
                    break;
                case 1: /**公选课*/
                    RobConfiguration.ROB_COURSE_TYPE = EnumCourseType.COMMON;
                    break;
            }
            user = MysqlUtil.getUser(null);
            /**备份线程*/
            saveCookieManager.startBackupCookie();/**开启备份Cookie线程*/
            saveRobberManager.startBackupRobberInfo();/**开启备份Robber信息线程*/
            saveCoursesManager.startBackupCourseList(); /**开启课表备份线程*/
            saveCoursesManager.initBackupCourseList(); /**读取课表缓存*/
//            System.out.println("showTable:" + user);
            showTable(user);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}

